package com.yvon.core;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yvon.core.page.ListData;
import com.yvon.core.page.SearchCriteria;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author Yvon
 */
public class BaseServiceImpl<T, M extends BaseMapper<T>> extends ServiceImpl<M, T> implements IBaseService<T> {

    public BaseServiceImpl() {
    }

    @Override
    public ListData page(SearchCriteria searchCriteria) {
        IPage<T> page = searchCriteria.buildQuery(this.query()).page(searchCriteria.buildPage());
        return ListData.of(page);
    }

    @Override
    protected Class<T> currentModelClass() {
        ParameterizedType parameterizedType = (ParameterizedType)this.getClass().getGenericSuperclass();
        Type type = parameterizedType.getActualTypeArguments()[0];
        return (Class)type;
    }
}